<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace yiike\user\models;

use Yii;

/**
 * Description of User
 *
 * @author Administrator
 */
class Login extends \yii\base\Component {
    
    public function byPassword($login, $password)
    {
        $loginForm = Yii::createObject('dektrium\user\models\LoginForm');
        $loginForm->login = $login;
        $loginForm->password = $password;
        return $loginForm->login();
    }
    
    public function byToken($token)
    {
        $tokenModel = Token::findOne(['code' => $token, 'type' => Token::TYPE_LOGIN]);
        if ($tokenModel && ($user = $tokenModel->user)) {
            return Yii::$app->getUser()->login($user);
        } else {
            return false;
        }
    }
}
